#include "screens.h"

static void update_startup(int *quit)
{
    char        cond = 1;
    SDL_Event   event;

    while (cond)
    {
        SDL_WaitEvent(&event);
        switch (event.type)
        {
            case SDL_QUIT:
                *quit = 1;
                cond = 0;
                break;
            case SDL_MOUSEBUTTONDOWN:
                if (event.button.x >= 120 && event.button.x <= 980 &&
                    event.button.y >= 120 && event.button.y <= 370)
                    cond = 0;
                else if (event.button.x >= 120 && event.button.x <= 980 &&
                    event.button.y >= 560 && event.button.y <= 820)
                {
                    *quit = 1;
                    cond = 0;
                }
                break;
        }
    }
}

static void update_endgame()
{
    char        cond = 1;
    SDL_Event   event;

    while (cond)
    {
        SDL_WaitEvent(&event);
        switch (event.type)
        {
            case SDL_QUIT:
                cond = 0;
                break;
            case SDL_MOUSEBUTTONDOWN:
                cond = 0;
                break;
        }
    }
}

/**
** @brief Display the MENU screen !
**
** @param Object structure
*/
int start_up(s_object *object)
{
    int             quit = 0;
    SDL_Rect        pos = {.x = 0, .y = 0};
    SDL_Surface     *img = NULL;

    img = IMG_Load("../check/img/menu.jpg");
    SDL_BlitSurface(img, NULL, object->screen, &pos);

    SDL_Flip(object->screen);

    update_startup(&quit);

    SDL_FreeSurface(img);

    return (quit);
}

/**
** @brief Display the FAIL screen !
**
** @param Object structure
*/
void screen_fail(s_object *object)
{
    SDL_Rect        pos = {.x = 0, .y = 0};
    SDL_Surface     *img = NULL;

    img = IMG_Load("../check/img/fail.jpg");
    SDL_BlitSurface(img, NULL, object->screen, &pos);

    SDL_Flip(object->screen);

    update_endgame();

    SDL_FreeSurface(img);
}

/**
** @brief Display the WIN screen !
**
** @param Object structure
*/
void screen_win(s_object *object)
{
    SDL_Rect        pos = {.x = 0, .y = 0};
    SDL_Surface     *img = NULL;

    img = IMG_Load("../check/img/win.jpg");
    SDL_BlitSurface(img, NULL, object->screen, &pos);

    SDL_Flip(object->screen);

    update_endgame();

    SDL_FreeSurface(img);
}
